package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;


public class SpIncidentEditAssetsPageUtil extends SeleniumPageUtil {

	public final static By IEA_LINK_SAVE = By.id("IncidentAsset1_btnSave");
	public final static By IEA_LINK_SDA = By.id("IncidentAsset1_btnSelectDifferentAsset");
	public final static By IEA_LINK_CLEAR = By.id("IncidentAsset1_btnClear");
	public final static By IEA_SPAN_TITLE = By.id("IncidentAsset1_lblHdr");
	public final static By IEA_TD_ASSETS = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr/td[1]/table/tbody/tr[1]/td[1]");
	public final static By IEA_TD_ASSETS_VALUE = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr/td[1]/table/tbody/tr[1]/td[2]");
	public final static By IEA_TD_DETAIL = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[2]/td");
	public final static By IEA_TD_TYPE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[3]/td[1]");
	public final static By IEA_TD_TYPE_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[3]/td[2]");
	public final static By IEA_TD_MFG = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[4]/td[1]");
	public final static By IEA_TD_MFG_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[4]/td[2]");
	public final static By IEA_TD_MODEL = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[5]/td[1]");
	public final static By IEA_TD_MODEL_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[5]/td[2]");
	public final static By IEA_TD_SER_NUM = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[6]/td[1]");
	public final static By IEA_TD_SER_NUM_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[6]/td[2]");
	public final static By IEA_TD_ASSET_NAME = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[7]/td[1]");
	public final static By IEA_TD_ASSET_NAME_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[7]/td[2]");
	public final static By IEA_TD_ASSETS_DESC = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[8]/td[1]");
	public final static By IEA_TD_ASSETS_DESC_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[8]/td[2]");
	public final static By IEA_TD_ASSETS_STATUS = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[9]/td[1]");
	public final static By IEA_TD_ASSETS_STATUS_VALUE = By.xpath("//*[@id='IncidentAsset1_pnlAsset']/table/tbody/tr[9]/td[2]");
	public final static By IEA_SPAN_SER_PARTNER = By.id("IncidentAsset1_lblServicePartner");
	public final static By IEA_INPPUT_SER_PARTNER = By.id("IncidentAsset1_txtPartner");
	public final static By IEA_TD_ERROR_CODE = By.xpath("//*[@id='IncidentAsset1_tblErrCode']/tbody/tr[1]/td[1]");
	public final static By IEA_INPUT_ERROR_CODE = By.id("IncidentAsset1_txtErrCode");
	public final static By IEA_TD_ERROR_DESC = By.xpath("//*[@id='IncidentAsset1_tblErrCode']/tbody/tr[2]/td[1]");
	public final static By IEA_TEXTAREA_ERROR_DESC = By.id("IncidentAsset1_txtErrDescription");
	public final static By IEA_SPAN_NOTES = By.xpath("//*[@id='IncidentAsset1_tblErrCode']/tbody/tr[3]/td/span");
	public static void enterAsset(String incientId){
		// login into homepage
		SpSearchPageUtil.enter();
		// current window handle
		// make sure search button and incident id input text show
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_BUTTON_SEARCH)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_MAIN_INPUT_INCIDENT_ID)));
		// click the incident id link to enter the edit page
		SpIncidentEditPageUtil.enterIncidentID(incientId);
		//click Assets link to enter incident/Asset edit page
		SeleniumUtil.click(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_LINK_TAB_ASSETS));
		waitForPageToLoad();
	}
	public static void waitForPageToLoad(){
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.waitOnElements(new By[]{
				IEA_LINK_SAVE,IEA_TEXTAREA_ERROR_DESC,IEA_INPUT_ERROR_CODE
		});
	}
}
